package com.net.jef.webx.fen.tool.module.screen;

import java.util.List;
import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.Navigator;
import com.alibaba.citrus.turbine.dataresolver.Param;
import com.net.jef.util.HttpClientHelper;

public class MobileService {
    // http://www.youdao.com/smartresult-xml/search.s?type=ip&q=42.120.16.111
    //http://whois.www.net.cn/whois/api_whois?host=sina.com.cn
    
//    获取Ip所在地：
//    http://www.youdao.com/smartresult-xml/search.s?type=ip&q=58.30.32.61<!---->
//    <?xml version="1.0" encoding="gbk"?>
//    <smartresult>
//    <product type="ip">
//    <ip>61.172.201.194</ip>
//    <location>上海市 电信张江机房</location>
//    </product>
//    </smartresult>


    
//    身份证信息：
//    http://www.youdao.com/smartresult-xml/search.s?type=id&q=232700198910206016<!---->
//
//    获取手机所在地：
//    http://www.youdao.com/smartresult-xml/search.s?type=mobile&q=13671151172<!---->
    
    private static Pattern      mobilePattern = null;
    
    static {
        try {
            mobilePattern = Pattern.compile("\\d{11}");

        } catch (Exception e) {
        }
    }
    public void execute(@Param("code") String code, Context context,
            Navigator nav,HttpServletRequest request) throws Exception {
        
        if(code==null) {
           return;
        }else{
            code=code.trim();
        }

     
        String mobileResultStr = HttpClientHelper
                .getHtml(
                        "http://www.youdao.com/smartresult-xml/search.s?type=mobile&q="+code,
                        "GBK", 15);
        
        
        Document xmlDoc = DocumentHelper.parseText(mobileResultStr);  
        List<Element> list= xmlDoc.selectNodes("//location");
        if(list.size()> 0){
            context.put("mobileResult", list.get(0).getText());            
        }
        
        context.put("code",code);

    }
    
}
